//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussLegendreIntegration.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#include <gen/QL/Math/Integrals/GaussianQuadrature.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (UInt64 n) : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussLegendreIntegration = NULL;
#endif
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n);
        _ppGaussLegendreIntegration = new boost::shared_ptr<QuantLib::GaussLegendreIntegration> (new QuantLib::GaussLegendreIntegration ( _n ));
        SetGaussianQuadrature (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (boost::shared_ptr<QuantLib::GaussLegendreIntegration>& childNative, Object^ owner) : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLegendreIntegration = NULL;
#endif
	_ppGaussLegendreIntegration = &childNative;
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
}
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (QuantLib::GaussLegendreIntegration& childNative, Object^ owner) : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLegendreIntegration = NULL;
#endif
	_ppGaussLegendreIntegration = new boost::shared_ptr<QuantLib::GaussLegendreIntegration> (&childNative);
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
    _GaussLegendreIntegrationOwner = owner;
    _GaussianQuadratureOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (CGaussLegendreIntegration^ copy) : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLegendreIntegration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussLegendreIntegration = new boost::shared_ptr<QuantLib::GaussLegendreIntegration> (copy->GetShared());
        _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
    }
}
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (System::Type^ t) : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLegendreIntegration = NULL;
#endif
	if (!t->IsSubclassOf(CGaussLegendreIntegration::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (QuantLib::Handle<QuantLib::GaussLegendreIntegration>& childNative, Object^ owner)  : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
	_phGaussLegendreIntegration = &childNative;
	_ppGaussLegendreIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussLegendreIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
    _GaussLegendreIntegrationOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (QuantLib::Handle<QuantLib::GaussLegendreIntegration> childNative)  : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
	_phGaussLegendreIntegration = &childNative;
	_ppGaussLegendreIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussLegendreIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::CGaussLegendreIntegration (QuantLib::GaussLegendreIntegration childNative)  : CGaussianQuadrature(CGaussLegendreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLegendreIntegration = NULL;
#endif
	_ppGaussLegendreIntegration = new boost::shared_ptr<QuantLib::GaussLegendreIntegration> (new QuantLib::GaussLegendreIntegration (childNative));
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLegendreIntegration));
}
#endif

Cephei::QL::Math::Integrals::CGaussLegendreIntegration::~CGaussLegendreIntegration ()
{
    if (_ppGaussLegendreIntegration != NULL)
    {
	    delete _ppGaussLegendreIntegration;
        _ppGaussLegendreIntegration = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussLegendreIntegration::!CGaussLegendreIntegration ()
{
    if (_ppGaussLegendreIntegration != NULL)
    {
	    delete _ppGaussLegendreIntegration;
    }
}
QuantLib::GaussLegendreIntegration& Cephei::QL::Math::Integrals::CGaussLegendreIntegration::GetReference ()
{
    if (_ppGaussLegendreIntegration == NULL) throw gcnew NativeNullException ();
	return **_ppGaussLegendreIntegration;
}
boost::shared_ptr<QuantLib::GaussLegendreIntegration>& Cephei::QL::Math::Integrals::CGaussLegendreIntegration::GetShared ()
{
    if (_ppGaussLegendreIntegration == NULL) throw gcnew NativeNullException ();
	return *_ppGaussLegendreIntegration;
}
QuantLib::GaussLegendreIntegration* Cephei::QL::Math::Integrals::CGaussLegendreIntegration::GetPointer ()
{
    if (_ppGaussLegendreIntegration == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussLegendreIntegration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussLegendreIntegration>& Cephei::QL::Math::Integrals::CGaussLegendreIntegration::GetHandle ()
{
	if (_phGaussLegendreIntegration == NULL)
	{
		_phGaussLegendreIntegration = new Handle<QuantLib::GaussLegendreIntegration> (*_ppGaussLegendreIntegration);
	}
	return *_phGaussLegendreIntegration;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussLegendreIntegration::HasNative () 
{
	return (_ppGaussLegendreIntegration != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussLegendreIntegration^ Cephei::QL::Math::Integrals::CGaussLegendreIntegration_Factory::Create (UInt64 n)
{
    return gcnew CGaussLegendreIntegration ( n);
}
